package middleware

import "github.com/gin-gonic/gin"

func Cors(c *gin.Context) {

	c.Writer.Header().Set("Access-Control-Allow-Origin", c.GetHeader("Origin"))
	c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, PATCH")
	c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, SessionID, App-Key, Nonce, Timestamp, Signature")

	c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
	if c.Request.Method == "OPTIONS" {
		c.AbortWithStatus(204)
		return
	}

	c.Next()

}
